{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "241d5e48",
   "metadata": {},
   "source": [
    "* 2022/10/11 /week08\n",
    "* Python 课堂笔记"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "36dfa79f",
   "metadata": {},
   "source": [
    "# 本周内容"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d6548b74",
   "metadata": {},
   "source": [
    "* 代码的注释\n",
    "* 用户输入\n",
    "* 格式化输出"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b9b158b9",
   "metadata": {},
   "source": [
    "# 0. 代码的注释"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "151fcd2b",
   "metadata": {},
   "outputs": [],
   "source": [
    " #，一般写在代码块的最上边，或者每一行代码的最后，用于代码思路的记录。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2bab325a",
   "metadata": {},
   "source": [
    "# 1.用户输入\n",
    ">input"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "1fe831fb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号欧巴\n",
      "密码卡哇伊\n",
      "欧巴\n",
      "卡哇伊\n"
     ]
    }
   ],
   "source": [
    "# 登陆系统\n",
    "username = input(\"账号\")\n",
    "password = input(\"密码\")\n",
    "\n",
    "print(username)\n",
    "print(password)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "fdde9c6f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号:欧巴\n",
      "密码:卡哇伊\n",
      "欢迎欧巴登陆\n"
     ]
    }
   ],
   "source": [
    " # 登录系统 完善\n",
    " # 假设我们数据库有用户所有信息：账号：欧巴，密码：卡哇伊\n",
    "userl = \"欧巴\"\n",
    "password = \"卡哇伊\"\n",
    "\n",
    "username = input(\"账号:\")\n",
    "password = input(\"密码:\")\n",
    "\n",
    "# 情景一：输入信息正确，登陆成功\n",
    "if userl == username and password == password:\n",
    "    print(\"欢迎\"+userl+\"登陆\")\n",
    "# 情景二：账号不存在或密码不正确\n",
    "else:\n",
    "    print(\"阿多贝印度的，有问题\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "87e775e9",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "c6eb25af",
   "metadata": {},
   "source": [
    "# 2.格式化输出"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "b8f5f1d1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "姓名：欧巴\n",
      "年龄：16\n",
      "工作：打豆豆\n",
      "地区：宇宙\n",
      "-----INFO OF -----\n",
      "年龄：age\n",
      "工作：job\n",
      "收入：salary\n",
      "地区：reg\n"
     ]
    }
   ],
   "source": [
    "# 用户注册系统 方法一： 字符串拼接\n",
    "name = input(\"姓名：\")\n",
    "age = input(\"年龄：\")\n",
    "job = input(\"工作：\")\n",
    "salary = (\"收入：\")\n",
    "reg = input(\"地区：\")\n",
    "\n",
    "info = '''-----INFO OF -----\n",
    "年龄：age\n",
    "工作：job\n",
    "收入：salary\n",
    "地区：reg'''\n",
    "print(info)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "5123bb25",
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyboardInterrupt",
     "evalue": "Interrupted by user",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "Input \u001b[1;32mIn [8]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m age \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43minput\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m年龄：\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\python\\lib\\site-packages\\ipykernel\\kernelbase.py:1075\u001b[0m, in \u001b[0;36mKernel.raw_input\u001b[1;34m(self, prompt)\u001b[0m\n\u001b[0;32m   1071\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_allow_stdin:\n\u001b[0;32m   1072\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m StdinNotImplementedError(\n\u001b[0;32m   1073\u001b[0m         \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mraw_input was called, but this frontend does not support input requests.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m   1074\u001b[0m     )\n\u001b[1;32m-> 1075\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_input_request\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m   1076\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mstr\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mprompt\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1077\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_parent_ident\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mshell\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1078\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_parent\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mshell\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1079\u001b[0m \u001b[43m    \u001b[49m\u001b[43mpassword\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[0;32m   1080\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\python\\lib\\site-packages\\ipykernel\\kernelbase.py:1120\u001b[0m, in \u001b[0;36mKernel._input_request\u001b[1;34m(self, prompt, ident, parent, password)\u001b[0m\n\u001b[0;32m   1117\u001b[0m             \u001b[38;5;28;01mbreak\u001b[39;00m\n\u001b[0;32m   1118\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyboardInterrupt\u001b[39;00m:\n\u001b[0;32m   1119\u001b[0m     \u001b[38;5;66;03m# re-raise KeyboardInterrupt, to truncate traceback\u001b[39;00m\n\u001b[1;32m-> 1120\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyboardInterrupt\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInterrupted by user\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;28mNone\u001b[39m\n\u001b[0;32m   1121\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m:\n\u001b[0;32m   1122\u001b[0m     \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlog\u001b[38;5;241m.\u001b[39mwarning(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInvalid Message:\u001b[39m\u001b[38;5;124m\"\u001b[39m, exc_info\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m: Interrupted by user"
     ]
    }
   ],
   "source": [
    "age = input(\"年龄：\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "44dc95f5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "姓名：张智豪\n",
      "年龄：16\n",
      "工作：学习\n",
      "地区：宇宙\n",
      "-----INFO OF 张智豪 -----\n",
      "年龄：16 \n",
      "工作：学习 \n",
      "收入：收入： \n",
      "地区：宇宙 \n"
     ]
    }
   ],
   "source": [
    "# 用户注册系统 方法二： 占位符： %s,依次有序输入\n",
    "name = input(\"姓名：\")\n",
    "age = input(\"年龄：\")\n",
    "job = input(\"工作：\")\n",
    "salary = (\"收入：\")\n",
    "reg = input(\"地区：\")\n",
    "\n",
    "info = '''-----INFO OF %s -----\n",
    "年龄：%s \n",
    "工作：%s \n",
    "收入：%s \n",
    "地区：%s '''%(name,age,job,salary,reg)\n",
    "print(info)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0d15f87c",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 用户注册系统 方法三：format()格式化输出函数\n",
    "name = input(\"姓名：\")\n",
    "age = input(\"年龄：\")\n",
    "job = input(\"工作：\")\n",
    "salary = (\"收入：\")\n",
    "reg = input(\"地区：\")\n",
    "\n",
    "info ='''-----INFO {姓名}-----\n",
    "姓名：{姓名}\n",
    "年龄：{年龄}\n",
    "工作：{工作}\n",
    "收入：{收入}\n",
    "地区：{地区}'''.format"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "efd76837",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "efe70455",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
